package be.rivendale.renderer.mk2.remote;

import be.rivendale.renderer.mk2.Producer;
import be.rivendale.renderer.mk2.data.Queue;
import be.rivendale.renderer.mk2.data.Rectangle;
import be.rivendale.renderer.mk2.data.Segment;

import java.util.List;

public class Receiver extends Thread implements Producer {
    private SocketStreamer socketStreamer;
    private Queue<Segment> resultQueue;

    public Receiver(SocketStreamer socketStreamer, Queue<Segment> resultQueue) {
        super(Receiver.class.getSimpleName());
        this.socketStreamer = socketStreamer;
        this.resultQueue = resultQueue;
        start();
    }

    @Override
    public void run() {
        while(true) {
            resultQueue.put(socketStreamer.<Segment>read());
        }
    }

    @Override
    public void offerWork(List<Rectangle> rectangles) {
        socketStreamer.write(rectangles);
    }
}
